/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package parser;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 *
 * @author danil
 */
public class Parser {

    /**
     * @param args the command line arguments
     * @throws java.io.IOException
     */
    public static void main(String[] args) throws IOException, Exception {
        String page = getPage("http://drec.mipt.ru/index.html");
        //System.out.println(page);
        String regex = "(\\w+)@(\\w+\\.)(\\w+)(\\.\\w+)*" ;
        Pattern p = Pattern. compile (regex);
        Matcher m = p.matcher(page);
        while (m.find()) {
            System.out.println(m.group());
        }           
    }
    
    public static String getPage(String pageAddress) throws Exception {
        StringBuilder sb = new StringBuilder();
        URL pageURL = new URL(pageAddress);
        URLConnection uc = pageURL.openConnection();
        try (BufferedReader br = new BufferedReader(
                new InputStreamReader(
                        uc.getInputStream()))) {
            String inputLine;
            while ((inputLine = br.readLine()) != null) {
                sb.append(inputLine);
            }         
        }
        return sb.toString();
    }
    
}
